﻿Imports Model.Geometry

Namespace Midline
    Public Class Mid_Line
        Private _startpt As Point3d
        Private _startm As Double
        Private _startOri As SingleVector
        Private _endpt As Point3d
        Private _endm As Double
        Private _endOri As SingleVector
        Private _LineType As LineTypeList
        Private _offset As Double

        Public Property startpt() As Point3d
            Get
                Return _startpt
            End Get
            Set(value As Point3d)
                _startpt = value
            End Set
        End Property

        Public Property startm() As Double
            Get
                Return _startm
            End Get
            Set(value As Double)
                _startm = value
            End Set
        End Property

        Public Property startOri() As SingleVector
            Get
                Return _startOri
            End Get
            Set(value As SingleVector)
                _startOri = value
            End Set
        End Property

        Public Property endpt() As Point3d
            Get
                Return _endpt
            End Get
            Set(value As Point3d)
                _endpt = value
            End Set
        End Property

        Public Property endm() As Double
            Get
                Return _endm
            End Get
            Set(value As Double)
                _endm = value
            End Set
        End Property

        Public Property endOri() As SingleVector
            Get
                Return _endOri
            End Get
            Set(value As SingleVector)
                _endOri = value
            End Set
        End Property

        Public Property LineType() As LineTypeList
            Get
                Return _LineType
            End Get
            Set(value As LineTypeList)
                _LineType = value
            End Set
        End Property

        Public Property offset() As Double
            Get
                Return _offset
            End Get
            Set(value As Double)
                _offset = value
            End Set
        End Property
        ''' <summary>
        ''' 构造函数
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            LineType = LineTypeList.TypeLINE
            startpt = New Point3d()
            startm = 0
            endpt = New Point3d()
            startOri = New SingleVector()
            endOri = New SingleVector()
            endm = 0
            offset = 0
        End Sub
        ''' <summary>
        ''' 初始化所有元素
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function initMyself()
            startOri.V_x = endpt.p_x - startpt.p_x
            startOri.V_y = endpt.p_y - startpt.p_y
            startOri.V_z = endpt.p_z - startpt.p_z
            startOri.GetAzimuth()
            endOri = startOri
            If (endm = 0) Then
                endm = startm + startpt.GetDis3D(endpt)
            End If
            Return Nothing
        End Function
        ''' <summary>
        ''' 根据里程求点
        ''' </summary>
        ''' <param name="mil"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetPointByMileage(ByVal mil As Double) As Point3d
            If (mil >= startm And mil <= endm) Then
                Dim Dmil As Double = mil - startm
                Dim currpt As New Point3d()
                Dim t = Dmil / Math.Sqrt(Math.Pow(startOri.V_x, 2) + Math.Pow(startOri.V_y, 2) + Math.Pow(startOri.V_z, 2))
                currpt.p_x = startpt.p_x + startOri.V_x * t
                currpt.p_y = startpt.p_y + startOri.V_y * t
                currpt.p_z = startpt.p_z + startOri.V_z * t
                currpt.p_flag = 0
                Return currpt
            Else
                Return Nothing
            End If
        End Function
        ''' <summary>
        ''' 根据点获取平面
        ''' </summary>
        ''' <param name="pt"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetPlaneByPoint(ByVal pt As Point3d) As Plane
            Dim currplane As Plane = New Plane()
            currplane.praA = startOri.V_x
            currplane.praB = startOri.V_y
            currplane.praC = startOri.V_z
            currplane.praD = -1 * (currplane.praA * pt.p_x + currplane.praB * pt.p_y + currplane.praC * pt.p_z)
            currplane.normal_vector.V_x = startOri.V_x
            currplane.normal_vector.V_y = startOri.V_y
            currplane.normal_vector.V_z = startOri.V_z
            Return currplane
        End Function
    End Class
End Namespace